<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CANopenNode: socketCAN</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">CANopenNode
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__CO__socketCAN.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">Modules</a> &#124;
<a href="#files">Files</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">socketCAN</div>  </div>
</div><!--header-->
<div class="contents">

<p>Linux specific interface to CANopenNode.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
Modules</h2></td></tr>
<tr class="memitem:group__CO__socketCAN__driver__target"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN__driver__target.html">CO_driver_target.h</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__CO__socketCAN__ERROR"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN__ERROR.html">CAN errors &amp; Log</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__CO__socketCAN__OD__storage"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN__OD__storage.html">OD storage</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="files"></a>
Files</h2></td></tr>
<tr class="memitem:CO__Linux__threads_8h"><td class="memItemLeft" align="right" valign="top">file &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="CO__Linux__threads_8h.html">CO_Linux_threads.h</a></td></tr>
<tr class="memdesc:CO__Linux__threads_8h"><td class="mdescLeft">&#160;</td><td class="mdescRight">Helper functions for implementing CANopen threads in Linux. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga113aff6005a35eebd06e315575dbab2f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#ga113aff6005a35eebd06e315575dbab2f">threadMainWait_init</a> (<a class="el" href="group__CO__dataTypes.html#ga449976458a084f880dc8e3d29e7eb6f5">bool_t</a> CANopenConfiguredOK)</td></tr>
<tr class="memdesc:ga113aff6005a35eebd06e315575dbab2f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize mainline thread - blocking.  <a href="group__CO__socketCAN.html#ga113aff6005a35eebd06e315575dbab2f">More...</a><br /></td></tr>
<tr class="separator:ga113aff6005a35eebd06e315575dbab2f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac44e8243f658c04595067b0dc2f5199e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#gac44e8243f658c04595067b0dc2f5199e">threadMainWait_initOnce</a> (<a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> interval_us, <a class="el" href="group__CO__dataTypes.html#gadb828ef50c2dbb783109824e94cf6c47">int32_t</a> commandInterface, <a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> socketTimeout_ms, char *localSocketPath)</td></tr>
<tr class="memdesc:gac44e8243f658c04595067b0dc2f5199e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize once mainline thread - blocking.  <a href="group__CO__socketCAN.html#gac44e8243f658c04595067b0dc2f5199e">More...</a><br /></td></tr>
<tr class="separator:gac44e8243f658c04595067b0dc2f5199e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab65b24343e81090c4571854566e36d28"><td class="memItemLeft" align="right" valign="top"><a id="gab65b24343e81090c4571854566e36d28"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#gab65b24343e81090c4571854566e36d28">threadMainWait_close</a> (void)</td></tr>
<tr class="memdesc:gab65b24343e81090c4571854566e36d28"><td class="mdescLeft">&#160;</td><td class="mdescRight">Cleanup mainline thread - blocking. <br /></td></tr>
<tr class="separator:gab65b24343e81090c4571854566e36d28"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga213519b33bc491418ba7bfceaff9d5ff"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#ga213519b33bc491418ba7bfceaff9d5ff">threadMainWait_process</a> (<a class="el" href="group__CO__NMT__Heartbeat.html#gaf42f056a571b8e17a2d74428d1a49674">CO_NMT_reset_cmd_t</a> *reset)</td></tr>
<tr class="memdesc:ga213519b33bc491418ba7bfceaff9d5ff"><td class="mdescLeft">&#160;</td><td class="mdescRight">Process mainline thread - blocking.  <a href="group__CO__socketCAN.html#ga213519b33bc491418ba7bfceaff9d5ff">More...</a><br /></td></tr>
<tr class="separator:ga213519b33bc491418ba7bfceaff9d5ff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac83c768eff34e8c57af17aaad88982eb"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#gac83c768eff34e8c57af17aaad88982eb">CANrx_threadTmr_init</a> (<a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> interval_us)</td></tr>
<tr class="memdesc:gac83c768eff34e8c57af17aaad88982eb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize realtime thread.  <a href="group__CO__socketCAN.html#gac83c768eff34e8c57af17aaad88982eb">More...</a><br /></td></tr>
<tr class="separator:gac83c768eff34e8c57af17aaad88982eb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf1a4af36ebda476b998f3992b224dde5"><td class="memItemLeft" align="right" valign="top"><a id="gaf1a4af36ebda476b998f3992b224dde5"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#gaf1a4af36ebda476b998f3992b224dde5">CANrx_threadTmr_close</a> (void)</td></tr>
<tr class="memdesc:gaf1a4af36ebda476b998f3992b224dde5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Terminate realtime thread. <br /></td></tr>
<tr class="separator:gaf1a4af36ebda476b998f3992b224dde5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae029041c326cf257ac570e45d43f93ea"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CO__socketCAN.html#gae029041c326cf257ac570e45d43f93ea">CANrx_threadTmr_process</a> (void)</td></tr>
<tr class="memdesc:gae029041c326cf257ac570e45d43f93ea"><td class="mdescLeft">&#160;</td><td class="mdescRight">Process real-time thread.  <a href="group__CO__socketCAN.html#gae029041c326cf257ac570e45d43f93ea">More...</a><br /></td></tr>
<tr class="separator:gae029041c326cf257ac570e45d43f93ea"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Linux specific interface to CANopenNode. </p>
<p>CANopenNode runs on top of SocketCAN interface, which is part of the Linux kernel. For more info on Linux SocketCAN see <a href="https://www.kernel.org/doc/html/latest/networking/can.html">https://www.kernel.org/doc/html/latest/networking/can.html</a></p>
<p>CANopenNode runs in two threads:</p><ul>
<li>timer based real-time thread for CAN receive, SYNC and PDO, see <a class="el" href="group__CO__socketCAN.html#gae029041c326cf257ac570e45d43f93ea" title="Process real-time thread.">CANrx_threadTmr_process()</a></li>
<li>mainline thread for other processing, see <a class="el" href="group__CO__socketCAN.html#ga213519b33bc491418ba7bfceaff9d5ff" title="Process mainline thread - blocking.">threadMainWait_process()</a></li>
</ul>
<p>The "threads" specified here do not fork threads themselves, but require that two threads are provided by the calling application.</p>
<p>Main references for Linux functions used here are Linux man pages and the book: The Linux Programming Interface by Michael Kerrisk. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga113aff6005a35eebd06e315575dbab2f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga113aff6005a35eebd06e315575dbab2f">&#9670;&nbsp;</a></span>threadMainWait_init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void threadMainWait_init </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CO__dataTypes.html#ga449976458a084f880dc8e3d29e7eb6f5">bool_t</a>&#160;</td>
          <td class="paramname"><em>CANopenConfiguredOK</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize mainline thread - blocking. </p>
<p>Function must be called always in communication reset section, after <a class="el" href="group__CO__CANopen.html#gad85587d228b8ab0899a90c73ec0c7d9b" title="Initialize CANopenNode.">CO_CANopenInit()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">CANopenConfiguredOK</td><td>True, if node has successfully passed NMT initialization - it has a valid CANopen node-id, all CANopen objects are configured and CANopen runs normally. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gac44e8243f658c04595067b0dc2f5199e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac44e8243f658c04595067b0dc2f5199e">&#9670;&nbsp;</a></span>threadMainWait_initOnce()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void threadMainWait_initOnce </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a>&#160;</td>
          <td class="paramname"><em>interval_us</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__CO__dataTypes.html#gadb828ef50c2dbb783109824e94cf6c47">int32_t</a>&#160;</td>
          <td class="paramname"><em>commandInterface</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a>&#160;</td>
          <td class="paramname"><em>socketTimeout_ms</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>localSocketPath</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize once mainline thread - blocking. </p>
<p>Function must be called only once, before node starts operating.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">interval_us</td><td>Interval of the <a class="el" href="group__CO__socketCAN.html#ga213519b33bc491418ba7bfceaff9d5ff" title="Process mainline thread - blocking.">threadMainWait_process()</a> </td></tr>
    <tr><td class="paramname">commandInterface</td><td>Command interface type from CO_commandInterface_t </td></tr>
    <tr><td class="paramname">socketTimeout_ms</td><td>Timeout for established socket connection in [ms] </td></tr>
    <tr><td class="paramname">localSocketPath</td><td>File path, if commandInterface is local socket </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga213519b33bc491418ba7bfceaff9d5ff"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga213519b33bc491418ba7bfceaff9d5ff">&#9670;&nbsp;</a></span>threadMainWait_process()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> threadMainWait_process </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CO__NMT__Heartbeat.html#gaf42f056a571b8e17a2d74428d1a49674">CO_NMT_reset_cmd_t</a> *&#160;</td>
          <td class="paramname"><em>reset</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Process mainline thread - blocking. </p>
<p>threadMainWait is non-realtime thread for CANopenNode processing. It is initialized by <a class="el" href="group__CO__socketCAN.html#ga113aff6005a35eebd06e315575dbab2f" title="Initialize mainline thread - blocking.">threadMainWait_init()</a>. There is no configuration for CANopen objects. But there is configuration for epool, interval timer and eventfd. Function must be called inside loop. It blocks for correct time and unblocks automatically in case of event. It calls <a class="el" href="group__CO__CANopen.html#ga7a36da54b801074032622708e06a742e" title="Process CANopen objects.">CO_process()</a> function for processing mainline CANopen objects. For more basic function see threadMain_process() alternative.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">reset</td><td>return value from <a class="el" href="group__CO__CANopen.html#ga7a36da54b801074032622708e06a742e" title="Process CANopen objects.">CO_process()</a> function.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>time difference since last call in microseconds </dd></dl>

</div>
</div>
<a id="gac83c768eff34e8c57af17aaad88982eb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac83c768eff34e8c57af17aaad88982eb">&#9670;&nbsp;</a></span>CANrx_threadTmr_init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void CANrx_threadTmr_init </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a>&#160;</td>
          <td class="paramname"><em>interval_us</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize realtime thread. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">interval_us</td><td>Interval of periodic timer in microseconds, recommended value for realtime response: 1000 us </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gae029041c326cf257ac570e45d43f93ea"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae029041c326cf257ac570e45d43f93ea">&#9670;&nbsp;</a></span>CANrx_threadTmr_process()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CO__dataTypes.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> CANrx_threadTmr_process </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Process real-time thread. </p>
<p>CANrx_threadTmr is realtime thread for CANopenNode processing. It is initialized by <a class="el" href="group__CO__socketCAN.html#gac83c768eff34e8c57af17aaad88982eb" title="Initialize realtime thread.">CANrx_threadTmr_init()</a>. There is no configuration for CANopen objects. But configuration for epool event notification facility is included in <a class="el" href="group__CO__driver.html#ga3a1131813110529494cee5e27c0bf28d" title="Initialize CAN module object.">CO_CANmodule_init()</a> from CO_driver.c. Epool is configured to monitor the following file descriptors: notify pipe, CANrx sockets from all interfaces and interval timer.</p>
<p><a class="el" href="group__CO__socketCAN.html#gae029041c326cf257ac570e45d43f93ea" title="Process real-time thread.">CANrx_threadTmr_process()</a> blocks on epoll_wait(). This is implemented inside <a class="el" href="group__CO__socketCAN__driver__target.html#ga57af27dfaaec8355e89fef506799a4b9" title="Functions receives CAN messages (blocking)">CO_CANrxWait()</a> from CO_driver.c. New CAN message is processed in <a class="el" href="group__CO__socketCAN.html#gae029041c326cf257ac570e45d43f93ea" title="Process real-time thread.">CANrx_threadTmr_process()</a> function, which calls <a class="el" href="group__CO__CANopen.html#gaad5c15c3ca475912661f512d37413b12" title="Process CANopen SYNC objects.">CO_process_SYNC()</a>, <a class="el" href="group__CO__CANopen.html#ga4318848921c35e8bb5a7d97dca5668a0" title="Process CANopen RPDO objects.">CO_process_RPDO()</a> and <a class="el" href="group__CO__CANopen.html#ga8c62a2afd2762d99e9c9be13a3d9a7a8" title="Process CANopen TPDO objects.">CO_process_TPDO()</a> functions for each expired timer interval. This function must be called inside an infinite loop.</p>
<dl class="section remark"><dt>Remarks</dt><dd>If realtime is required, this thread must be registered as such in the Linux kernel.</dd></dl>
<dl class="section return"><dt>Returns</dt><dd>Number of interval timer passes since last call. </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sat Sep 19 2020 10:03:21 for CANopenNode by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>
